package com.example.administrator.yuejian_15.activity;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.administrator.yuejian_15.R;
import com.example.administrator.yuejian_15.bean.MyBean;
import com.example.administrator.yuejian_15.bean.SuccessBean;
import com.example.administrator.yuejian_15.listener.TListener;
import com.example.administrator.yuejian_15.model.MyModel;
import com.example.administrator.yuejian_15.model.SetUserInfoModel;


public class SetUserInfoActivity extends BaseActivity implements View.OnClickListener {

    ImageView szus_fh;
    EditText szus_phone,szus_email;
    Button szus_botton;
    String uid;

    @Override
    void initView() {
        setLayout_file(R.layout.activity_set_user_info);
        szus_fh=(ImageView)findViewById(R.id.szus_fh);
        szus_phone=(EditText)findViewById(R.id.szus_phone);
        szus_email=(EditText)findViewById(R.id.szus_email);
        szus_botton=(Button)findViewById(R.id.szus_botton);

        MyModel myModel=new MyModel();
        uid=getid();
        myModel.myinfo(uid,myBeanTListener);
    }

    @Override
    void initEvent() {
        szus_fh.setOnClickListener(this);
        szus_botton.setOnClickListener(this);

    }

    @Override
    void initDate() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.szus_fh:
                finish();
                break;
            case R.id.szus_botton:
                String uid = getid();
                String phone = szus_phone.getText().toString().trim();
                String email = szus_email.getText().toString().trim();
                if (phone.equals("")||email.equals("")){
                    Toast.makeText(SetUserInfoActivity.this,"修改信息不能为空",Toast.LENGTH_SHORT).show();
                }
                else{
                    SetUserInfoModel setUserInfoModel = new SetUserInfoModel();
                    setUserInfoModel.setUserInfo(uid,phone,email,successBeanTListener);
                }

        }
    }

    TListener<MyBean> myBeanTListener=new TListener<MyBean>() {
        @Override
        public void onResponse(MyBean myBean) {
            String phone1 = myBean.getUphone();
            String email1 = myBean.getUemail();
            szus_phone.setText(phone1);
            szus_email.setText(email1);

        }

        @Override
        public void onFail(String msg) {

        }
    };

    TListener<SuccessBean> successBeanTListener = new TListener<SuccessBean>() {
        @Override
        public void onResponse(SuccessBean successBean) {
            String success = successBean.getSuccess();
            if (success.equals("1")){
                Toast.makeText(SetUserInfoActivity.this,"修改信息成功",Toast.LENGTH_SHORT).show();
                finish();
            }
            else if (success.equals("2")){
                Toast.makeText(SetUserInfoActivity.this,"电话号码已被别人注册，请重新输入",Toast.LENGTH_SHORT).show();
            }
            else{
                Toast.makeText(SetUserInfoActivity.this,"修改信息失败",Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(SetUserInfoActivity.this,"修改信息失败或网络错误",Toast.LENGTH_SHORT).show();

        }
    };
}
